package org.wyf.EveryPoint.system.controller;

import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.wyf.EveryPoint.common.annotation.ControllerEndpoint;
import org.wyf.EveryPoint.common.controller.BaseController;
import org.wyf.EveryPoint.common.entity.FebsResponse;
import org.wyf.EveryPoint.system.entity.Config;
import org.wyf.EveryPoint.system.service.IConfigService;

import java.util.Collection;
import java.util.List;

/**
 * 参数管理Controller
 * @author guanjh
 * 
 */
@Controller
@RestController
@RequiredArgsConstructor
@RequestMapping("conf")
public class ConfigController extends BaseController {
    
    private final IConfigService configService;

    @ResponseBody
    @RequestMapping("findAll")
    @RequiresPermissions("conf:view")
    public FebsResponse findAll() {
//    	List<Config> list = configService.findList(null);
        return new FebsResponse().success();
    }

    /**
     * 新增/修改 操作
     * @param confList
     * @return
     */
    @PostMapping("save")
    @ResponseBody
    @RequiresPermissions("conf:save")
    public FebsResponse saveOrUpdate(@RequestBody List<Config> confList)  {
//    	configService.batchInsertOrUpdate(confList);
    	return new FebsResponse().success().message("保存成功");
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @ResponseBody
    @PostMapping("deleteMany")
    @RequiresPermissions("conf:delete")
    @ControllerEndpoint(operation = "删除系统配置", exceptionMessage = "删除系统配置失败")
    public FebsResponse deleteMany(String ids) {
//    	configService.deleteMany(ids.split(","));
    	return new FebsResponse().success().message("删除成功");
    }

    /**
     * 清除所有缓存
     * @return
     */
    @GetMapping("clearCache")
    @ResponseBody
    @RequiresPermissions("conf:clearCache")
	public FebsResponse clearCache() {
//		Collection<String> list = cacheManager.getCacheNames();
//		for(String name : list) {
//			if(name.contains("Service") || name.contains("container-cache")) {
//				Cache cache = cacheManager.getCache(name);
//				cache.clear();
//			}
//		}
		return new FebsResponse().success().message("清除成功");
		
	}

}
